package avicit.im.lantop.archiveclassmanager.service.impl;

import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.im.lantop.archiveclassmanager.service.ArchiveClassManagerIntfsService;
import avicit.im.lantop.basic.archiveclassmanager.domain.LantopArchiveClass;
import avicit.im.lantop.userauthset.service.UserAuthIntfsService;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.Pinyin4jUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.service.ServiceBase;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：钟一华</p>
 * <p>邮箱：feifan1985@163.com</p>
 * <p>创建时间： 2014-11-4 下午5:48:37 </p>
 * <p>类说明：档案分类数接口实现类</p>
 * <p>修改记录： </p>
 */
@Service
@SuppressWarnings({"deprecation", "unchecked"})
public class ArchiveclassmanagerIntfsServiceImpl extends ServiceBase implements ArchiveClassManagerIntfsService {

	@Resource
	private JdbcAvicit jdbcAvicit;

	@Autowired(required = false)
	private UserAuthIntfsService userAuthIntfsService;

	@Autowired(required = true)
	private CommTableManagerIntfsService commTableManagerIntfsService;

	/**
	 * 获取档案分类树信息（单条记录）
	 * @author 钟一华 
	 * @param Id
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassListInfoByIntfs(String id) throws Exception {
		String sql = "select lac.* from lantop_archive_class lac where lac.id = '" + id + "'";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		return list;
	}

	/**
	 * 获取档案分类树信息：列表展示（文件夹、模板、数据节点、物理表）
	 * @author 钟一华 
	 * @param 组织ID
	 * @param 单位ID	
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassListInfoToTableByIntfs(String orgId, String deptId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM LANTOP_ARCHIVE_NODE_TAB_V LACV\n");
		sbSql.append("WHERE LACV.ORG_ID = ?"); // 暂时不要deptId AND LACV.DEPT_ID = ?
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), orgId);
		return list;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点、物理表）
	 * @author 钟一华 
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToTableInfoByIntfs(String orgId, String deptId) throws Exception {
		List<TreeNode> nodes = this.getTreeNodeByOrgIdDeptId("", orgId, deptId);
		return nodes;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点、物理表）
	 * 通过id,orgid,deptid获得树节点数据
	 * @author 钟一华 
	 * @param id
	 * @param orgId
	 * @param deptId
	 * @return List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeByOrgIdDeptId(String id, String orgId, String deptId) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		List<Map<String, Object>> archiveClassList = this.findNodesByParentId(orgId, id);
		try {
			// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
			for (Map<String, Object> row : archiveClassList) {
				String rid = (String) row.get("id");
				String rname = (String) row.get("archive_class_node_name");
				String rOrgId = (String) row.get("org_id");
				String rDeptId = (String) row.get("dept_id");
				TreeNode node = new TreeNode();
				node.setId(rid);
				node.setText(rname);
				String archiveType = (String) row.get("ARCHIVE_TYPE");
				String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
				String rootId = (String) row.get("PARENT_ID");
				// 根据节点类型,设置节点图标
				if (null != rootId && "ROOT".equals(rootId)) { // 根节点
					node.setIconCls("icon-im-newnorg");
				} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
					node.setIconCls("icon-im-newntable");
				} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
					node.setIconCls("icon-im-newnmodulefile");
				} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
					node.setIconCls("icon-im-newnmodulelib");
				} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
					node.setIconCls("icon-im-newnmodulefile");
				} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
					node.setIconCls("icon-im-newndatanode");
				}
				node.setAttributes(row);
				BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
				if (null != childCount2 && childCount2.longValue() > 0) {
					List<TreeNode> cnodes = this.getTreeNodeByOrgIdDeptId(rid, rOrgId, rDeptId);
					node.setChildren(cnodes);
					node.setState("open");
				} else {
					node.setState("open");
				}
				nodeList.add(node);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return nodeList;
	}

	/**
	 * 根据查询条件返回查询树形结果
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param param
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToSearchByIntfs(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		//userID
		String userId =(String) param.get("targetId");
		// 档案类型
		String archiveType = (String) param.get("archiveType");
		// 查询条件
		String searchValue = (String) param.get("searchValue");
		// 交通部标识符
		String jtbFlag = (String) param.get("jtbFlag");
		//档案整理模糊查询标识
		String BS = (String) param.get("BS");
		String typeSql = "SELECT * FROM LANTOP_ARCHIVE_CLASS WHERE ARCHIVE_TYPE = '" + archiveType + "' and ORG_ID='" + orgId + "'";
		// 根据档案类型查询节点数据
		List<Map<String, Object>> typeList = this.jdbcAvicit.getJdbcTemplate().queryForList(typeSql);
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T WHERE \n");
		for (int i = 0; i < typeList.size(); i++) {
			Map<String, Object> typeMap = typeList.get(i);
			String path = (String) typeMap.get("ARCHIVE_CLASS_NODE_PATH");
			sb.append("INSTR('" + path + "', T.ARCHIVE_CLASS_NODE_PATH) > 0\n");
			if (i != typeList.size() - 1) {
				sb.append(" OR ");
			}
		}
		sb.append("UNION ALL \n");
		sb.append("SELECT * FROM (\n");
		sb.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T WHERE");
		for (int i = 0; i < typeList.size(); i++) {
			Map<String, Object> typeMap = typeList.get(i);
			String path = (String) typeMap.get("ARCHIVE_CLASS_NODE_PATH");
			sb.append("(INSTR( T.ARCHIVE_CLASS_NODE_PATH,'" + path + "') > 0\n");
			sb.append("AND T.ARCHIVE_CLASS_NODE_PATH != '" + path + "')");
			if (i != typeList.size() - 1) {
				sb.append(" OR ");
			}
		}
		sb.append("CONNECT BY PRIOR T.ID = T.PARENT_ID\n");
		sb.append("START WITH T.PARENT_ID IN (");
		for (int i = 0; i < typeList.size(); i++) {
			Map<String, Object> typeMap = typeList.get(i);
			String id = (String) typeMap.get("ID");
			sb.append("'" + id + "'");
			if (i != typeList.size() - 1) {
				sb.append(",");
			}
		}
		sb.append(")) A \n");
		sb.append("WHERE A.PARENT_ID IN (");
		for (int i = 0; i < typeList.size(); i++) {
			Map<String, Object> typeMap = typeList.get(i);
			String id = (String) typeMap.get("ID");
			sb.append("'" + id + "'");
			if (i != typeList.size() - 1) {
				sb.append(",");
			}
		}
		sb.append(") AND ARCHIVE_CLASS_NODE_CODE NOT IN ('BMWJ', 'GRWJ')");
		if (null != jtbFlag && !"".equals(jtbFlag) && !"null".equals(jtbFlag)) {
			sb.append(" AND UPPER(REPLACE(REPLACE(REMARK,CHR(10), ''), ' ', '')) = '" + jtbFlag.trim().toUpperCase() + "'");
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM (");
		sbSql.append(sb);
		sbSql.append(") B WHERE B.ARCHIVE_CLASS_NODE_NAME LIKE '%" + searchValue + "%'");

		StringBuffer sbs = new StringBuffer();
		sbs.append("AND B.ARCHIVE_CLASS_NODE_NAME IN ");
		sbs.append("(SELECT CART.NAME FROM CBB_AUTH_RESOURCE CART ");
		sbs.append("LEFT JOIN LANTOP_USER_AUTH_SET_EXTEND LUASE ");
		sbs.append("ON CART.ID = LUASE.CBB_AUTH_RESOURCE_ID ");
		sbs.append("WHERE ((CART.TARGET_TYPE = '2' AND EXISTS ");
		sbs.append("(SELECT DEPT_ID FROM BPM_DEF_USER_DEPT_POSITION_V T ");

		sbs.append("WHERE T.DEPT_ID = CART.TARGET_ID ");
		sbs.append("AND T.USER_ID = '"+userId+"' ");
		sbs.append("AND T.ORG_IDENTITY = '"+orgId+"' ");
		sbs.append(")) ");
		if(BS != null){
			sbs.append("OR (CART.TARGET_TYPE = '1' AND EXISTS ");
			sbs.append("(SELECT SYS_ROLE_ID FROM SYS_USER_ROLE T ");
			sbs.append("WHERE T.SYS_ROLE_ID = CART.TARGET_ID ");
			sbs.append("AND T.SYS_USER_ID = '"+userId+"' ");
			sbs.append("AND T.ORG_IDENTITY = '"+orgId+"')) ");
			sbs.append("OR (CART.TARGET_ID = '1' AND CART.TARGET_TYPE = '3')");
			sbs.append("OR (CART.TARGET_TYPE = '4' AND EXISTS ");
			sbs.append("(SELECT POSITION_ID FROM BPM_DEF_USER_DEPT_POSITION_V T ");
			sbs.append("WHERE T.POSITION_ID = CART.TARGET_ID ");
			sbs.append("AND T.USER_ID = '"+userId+"' ");
			sbs.append("AND T.ORG_IDENTITY = '"+orgId+"')) ");
		}
		sbs.append(") AND CART.ORG_ID = '"+orgId+"' ");
		sbs.append("AND CART.SYS_ID = '"+sysId+"' ");
		sbs.append("AND CART.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET')");

		sbSql.append(sbs);

		List<Map<String, Object>> searchList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		List<TreeNode> nodes = this.getTreeNodeByParentIdByIntfs(orgId, deptId, sysId, sb, "ROOT", searchList);
		return nodes;
	}

	/**
	 * 根据档案类型查询
	 * @param archiveType
	 * @return
	 * @throws Exception List<String>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeByParentIdByIntfs(String orgId, String deptId, String sysId, StringBuffer sb, String parentId, List<Map<String, Object>> searchList) throws Exception {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		List<Map<String, Object>> archiveClassList = this.getTreeListByParentId(sb, parentId, searchList);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = this.getTreeNodeByParentIdByIntfs(orgId, deptId, sysId, sb, rid, searchList);
				node.setChildren(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodeList.add(node);
		}
		return nodeList;
	}

	public List<Map<String, Object>> getTreeListByParentId(StringBuffer sb, String parentId, List<Map<String, Object>> searchList) throws Exception {
		StringBuffer resultSql = new StringBuffer();
		resultSql.append("WITH TREE AS (\n");
		resultSql.append("SELECT * FROM (");
		resultSql.append(sb + ") BB WHERE \n");
		if (searchList.size() > 0) {
			for (int i = 0; i < searchList.size(); i++) {
				Map<String, Object> searchMap = searchList.get(i);
				String path = (String) searchMap.get("ARCHIVE_CLASS_NODE_PATH");
				resultSql.append(" INSTR('" + path + "', BB.ARCHIVE_CLASS_NODE_PATH) > 0");
				if (i != searchList.size() - 1) {
					resultSql.append(" OR ");
				}
			}
		} else {
			resultSql.append(" 1 = 2 ");
		}

		resultSql.append(") SELECT (SELECT COUNT(*) FROM TREE TR2 \n");
		resultSql.append("WHERE TR2.PARENT_ID = TR1.ID) CHILD_COUNT, TR1.*\n");
		resultSql.append("FROM TREE TR1\n");
		resultSql.append("WHERE TR1.PARENT_ID = '" + parentId + "'\n");
		resultSql.append("AND ARCHIVE_CLASS_NODE_CODE NOT IN ('BMWJ', 'GRWJ')\n");
		resultSql.append("ORDER BY TR1.NODE_SORT_NUMBER ASC, TR1.CREATION_DATE ASC");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(resultSql.toString());
		return list;
	}

	/**
	 * 获取档案分类树信息，通过节点路径向上+向下查找：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华 
	 * @param nodePath
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfs(String nodePath) throws Exception {
		String pid = this.getSelectSqlByNodePath(nodePath);
		List<TreeNode> list = this.getTreeNodeByNodePathToDataNodeInf(pid, nodePath);
		return list;
	}

	/**
	 * 获取档案分类树信息，通过节点路径向上+向下查找：树形展示（文件夹、模板、数据节点）
	 * 通过path获得父节点id
	 * @author 钟一华
	 * @return
	 * @throws Exception String
	 * @throws
	 */
	public String getSelectSqlByNodePath(String nodePath) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH A AS (SELECT T.* FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("WHERE INSTR('" + nodePath + "', T.ARCHIVE_CLASS_NODE_PATH) > 0\n");
		sbSql.append("UNION ALL\n");
		sbSql.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("WHERE INSTR(T.ARCHIVE_CLASS_NODE_PATH, '" + nodePath + "') > 0\n");
		sbSql.append("AND T.ARCHIVE_CLASS_NODE_PATH != '" + nodePath + "')\n");
		sbSql.append("SELECT MAX(LENGTH(A.ARCHIVE_CLASS_NODE_PATH)) MX, A.PARENT_ID FROM A\n");
		sbSql.append("GROUP BY A.PARENT_ID ORDER BY MX");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		if (list.size() > 0) {
			Map<String, Object> map = list.get(0);
			String pid = map.get("parent_id").toString();
			return pid;
		}
		return null;
	}

	/**
	 * 获取档案分类树信息，通过节点路径向上+向下查找：树形展示（文件夹、模板、数据节点）
	 * 方法获得树节点数据通过路径获得向上+向下
	 * @author 钟一华
	 * 被调用方法getArchiveClassTreeNodeToDataNodeInfoByIntfs();
	 * @param parentId
	 * @param orgId
	 * @param deptId
	 * @return List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeByNodePathToDataNodeInf(String parentId, String nodePath) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdToDataNode(parentId, nodePath);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = this.getTreeNodeByNodePathToDataNodeInf(rid, nodePath);
				node.setChildren(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodeList.add(node);
		}
		return nodeList;
	}

	/**
	 * 获取档案分类树信息，通过节点路径向上+向下查找：树形展示（文件夹、模板、数据节点）
	 * 向上+向下查询
	 * @author 钟一华
	 * @param orgId
	 * @param parentId
	 * @param deptId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> findNodesByParentIdToDataNode(String pId, String nodePath) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH A AS (\n");
		sbSql.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("WHERE INSTR('" + nodePath + "', T.ARCHIVE_CLASS_NODE_PATH) > 0\n");
		sbSql.append("UNION ALL\n");
		sbSql.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("WHERE INSTR(T.ARCHIVE_CLASS_NODE_PATH, '" + nodePath + "') > 0\n");
		sbSql.append("AND T.ARCHIVE_CLASS_NODE_PATH != '" + nodePath + "')\n");
		sbSql.append("SELECT (SELECT COUNT(*) FROM A LAC2\n");
		sbSql.append("WHERE LAC2.PARENT_ID=LAC1.ID)\n");
		sbSql.append("CHILD_COUNT,LAC1.* FROM A LAC1\n");
		sbSql.append("WHERE LAC1.PARENT_ID = '" + pId + "' ORDER BY LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		return list;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华 
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfs(String orgId, String deptId) throws Exception {
		List<TreeNode> list = this.getTreeNodeToDataNodeInf("", orgId, deptId);
		return list;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点）
	 * 方法获得树节点数据
	 * @author 钟一华
	 * @param parentId
	 * @param orgId
	 * @param deptId
	 * @return List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeToDataNodeInf(String parentId, String orgId, String deptId) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdToDataNode(orgId, parentId, deptId);

		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			String rOrgId = (String) row.get("org_id");
			String rDeptId = (String) row.get("dept_id");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = this.getTreeNodeToDataNodeInf(rid, rOrgId, rDeptId);
				node.setChildren(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodeList.add(node);
		}
		return nodeList;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点）
	 * 获取子节点,对当前登陆用户的组织id和部门id进行过滤,只查询当前挡路用户组织和部门下的节点
	 * 被调用方法getTreeNodeToDataNodeInf();
	 * @param parentId
	 * @return 子节点集合
	 */
	public List<Map<String, Object>> findNodesByParentIdToDataNode(String orgId, String parentId, String deptId) {
		if ("".equals(parentId)) {
			parentId = "ROOT";
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT (SELECT COUNT(*)\n");
		sbSql.append("FROM LANTOP_ARCHIVE_CLASS LAC2\n");
		sbSql.append("WHERE LAC2.PARENT_ID = LAC1.ID\n");
		sbSql.append("AND LAC2.ORG_ID = ?\n");
		sbSql.append(") CHILD_COUNT, LAC1.*\n");
		sbSql.append("FROM LANTOP_ARCHIVE_CLASS LAC1\n");
		sbSql.append("WHERE LAC1.PARENT_ID = ?\n");
		sbSql.append("AND ARCHIVE_CLASS_NODE_CODE NOT IN ('BMWJ', 'GRWJ')\n");
		sbSql.append("ORDER BY LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC");
		Object[] objs = null;
		objs = new Object[2];
		objs[0] = orgId;
		objs[1] = parentId;
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), objs);
		return list;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板）
	 * @author 钟一华 
	 * @param orgId
	 * @param deptId
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToTemplateInfoByIntfs(String orgId, String deptId) throws Exception {
		List<TreeNode> list = this.getTreeNodeToTemplateInfoByInfs("", orgId, deptId);
		return list;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板）
	 * 查询树节点,过滤节点类型数据
	 * @author 钟一华
	 * @param orgId
	 * @param parentId
	 * @param deptId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeToTemplateInfoByInfs(String parentId, String orgId, String deptId) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdToTemplate(orgId, parentId);

		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = this.getTreeNodeToTemplateInfoByInfs(rid, orgId, deptId);
				node.setChildren(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodeList.add(node);
		}
		return nodeList;
	}

	/**
	 * 获取档案分类树信息：树形展示（文件夹、模板）
	 * 查询节点,过滤节点类型数据
	 * @author 钟一华
	 * @param orgId
	 * @param parentId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> findNodesByParentIdToTemplate(String orgId, String parentId) {
		if ("".equals(parentId)) {
			parentId = "ROOT";
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT (SELECT COUNT(*) FROM LANTOP_ARCHIVE_CLASS LAC2 \n");
		sbSql.append("WHERE LAC2.PARENT_ID = LAC1.ID) CHILD_COUNT, LAC1.* \n");
		sbSql.append("FROM LANTOP_ARCHIVE_CLASS LAC1 \n");
		sbSql.append("WHERE LAC1.PARENT_ID = ? AND LAC1.ARCHIVE_CLASS_NODE_TYPE NOT IN ('1','2') \n");
		sbSql.append("AND LAC1.ORG_ID = ? \n");
		sbSql.append("ORDER BY LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC");
		Object[] objs = new Object[2];
		objs[0] = parentId;
		objs[1] = orgId;
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), objs);
		return list;
	}

	/**
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * 根节点显示所传递档案类型对应的名称；
	 * @author 钟一华 
	 * @param orgId
	 * @param deptId
	 * @param archiveType
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfs(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> params) throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("targetId", params.get("targetId"));
		param.put("targetType", params.get("targetType"));
		param.put("orgId", orgId);
		param.put("deptId", deptId);
		param.put("authType", "A1");
		param.put("sysId", sysId);
		param.put("orgIdentity", (String) params.get("orgIdentity"));
		String jtbFlag = (String) params.get("jtbFlag");
		//sanxiaFiles update by wuliang 2019.9.28 整理归档树权限变更
		List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveClassId(param);
		//List<String> authIds = this.userAuthIntfsService.getNodeListToDeptByUserId(param);
		//sanxiaFiles update by wuliang 2019.9.28  end
		// 获得数据集合sql
		String sql = this.getSelectSqlByOrgIdType(orgId, archiveType, authIds, jtbFlag);
		int level = 1;// 树展开的层级
		String parentId = (String) params.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
			level = 3;
		}
		if (params.containsKey("TREE_LEVEL") && null != params.get("TREE_LEVEL")) {
			String treeLevel = (String) params.get("TREE_LEVEL");
			level = Integer.parseInt(treeLevel);
		}
		List<TreeNode> nodeList = this.getTreeNodeToDataNodeInfoByInfs(orgId, archiveType, parentId, sql, level);
		return nodeList;
	}
	/**
	 *  整理归档专用
	 * @MethodName: getArchiveClassTreeNodeToDataNodeInfoByIntfsforZLGD
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param archiveType
	 * @param params
	 * @Return: java.util.List<avicit.platform6.commons.utils.web.TreeNode>
	 * @Author: 无量
	 * @Date: 2019/9/28 17:36
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfsforZLGD(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> params) throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("targetId", params.get("targetId"));
		param.put("targetType", params.get("targetType"));
		param.put("orgId", orgId);
		param.put("deptId", deptId);
		param.put("authType", "A1");
		param.put("sysId", sysId);
		param.put("orgIdentity", (String) params.get("orgIdentity"));
		String jtbFlag = (String) params.get("jtbFlag");
		//sanxiaFiles update by wuliang 2019.9.28 整理归档树权限变更
		//List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveClassId(param);
		List<String> authIds = this.userAuthIntfsService.getNodeListToDeptByUserId(param);
		//sanxiaFiles update by wuliang 2019.9.28  end
		// 获得数据集合sql
		String sql = this.getSelectSqlByOrgIdType(orgId, archiveType, authIds, jtbFlag);
		int level = 1;// 树展开的层级
		String parentId = (String) params.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
			level = 3;
		}
		if (params.containsKey("TREE_LEVEL") && null != params.get("TREE_LEVEL")) {
			String treeLevel = (String) params.get("TREE_LEVEL");
			level = Integer.parseInt(treeLevel);
		}
		List<TreeNode> nodeList = this.getTreeNodeToDataNodeInfoByInfs(orgId, archiveType, parentId, sql, level);
		return nodeList;
	}


	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfsToStatics(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> params) throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("targetId", params.get("targetId"));
		param.put("targetType", params.get("targetType"));
		param.put("orgId", orgId);
		param.put("deptId", deptId);
		param.put("sysId", sysId);
		String jtbFlag = (String) params.get("jtbFlag");
		param.put("orgIdentity", (String) params.get("orgIdentity"));
		List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveClassId(param);
		// 获得数据集合sql
		String sql = this.getSelectSqlByOrgIdType(orgId, archiveType, authIds, jtbFlag);
		int level = 1;// 树展开的层级
		String parentId = (String) params.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
			level = 4;
		}
		if (params.containsKey("TREE_LEVEL") && null != params.get("TREE_LEVEL")) {
			String treeLevel = (String) params.get("TREE_LEVEL");
			level = Integer.parseInt(treeLevel);
		}
		List<TreeNode> nodeList = this.getTreeNodeToDataNodeInfoByInfsItera(orgId, archiveType, parentId, sql, level);
		return nodeList;
	}


	/**
	 * 根据父节点id找到子节点数据
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param archiveType
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String,Object>>  getArchivesPlanMaintainNode(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> params) throws Exception {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("targetId", params.get("targetId"));
		param.put("targetType", params.get("targetType"));
		param.put("orgId", orgId);
		param.put("deptId", deptId);
		param.put("sysId", sysId);
		String jtbFlag = (String) params.get("jtbFlag");
		param.put("orgIdentity", (String) params.get("orgIdentity"));
		List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveClassId(param);
		// 获得数据集合sql
		String sql = this.getSelectSqlByOrgIdType(orgId, archiveType, authIds, jtbFlag);
		String parentId = (String) params.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
		}
		if (params.containsKey("TREE_LEVEL") && null != params.get("TREE_LEVEL")) {
			//String treeLevel = (String) params.get("TREE_LEVEL");
		}
		if ("".equals(sql)) {
			return null;
		}
		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdPathsToDataNode(parentId, sql);
		return archiveClassList;
	}
	

	/**
	 * 通过orgid,Type, parentId获得树节点
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华
	 * @param orgId
	 * @param archiveTpe
	 * @param parentId
	 * @return List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeToDataNodeInfoByInfs(String orgId, String archiveTpe, String parentId, String sql, int level) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		if ("".equals(sql)) {
			return nodeList;
		}
		if (level == 0) {
			return null;
		}
		level--;

		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdPathsToDataNode(parentId, sql);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			/*
			 * if (null != childCount2 && childCount2.longValue() > 0) { node.setChildren(cnodes); node.setState("open"); } else { node.setState("open"); }
			 */

			if (null != childCount2 && childCount2.longValue() > 0) {
				if (level > 0) {
					node.setState("open");
				} else {
					node.setState("closed");
				}
				node.setChildren(this.getTreeNodeToDataNodeInfoByInfs(orgId, archiveTpe, rid, sql, level));
			} else {
				node.setState("open");
			}

			nodeList.add(node);
		}
		return nodeList;
	}


	/**
	* @Title: getTreeNodeToDataNodeInfoByInfsItera
	* @Description:  通过orgid,Type, parentId获得树节点
	 * 	  获取档案分类树
	* @param [orgId, archiveTpe, parentId, sql, level]
	* @return java.util.List<avicit.platform6.commons.utils.web.TreeNode>
	* @date 2019-05-17
	* @author HuangJian
	*/
	public List<TreeNode> getTreeNodeToDataNodeInfoByInfsItera(String orgId, String archiveTpe, String parentId, String sql, int level) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		if ("".equals(sql)) {
			return nodeList;
		}
		if (level == 0) {
			return null;
		}
		level--;

		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdPathsToDataNode(parentId, sql);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			/*
			 * if (null != childCount2 && childCount2.longValue() > 0) { node.setChildren(cnodes); node.setState("open"); } else { node.setState("open"); }
			 */
			//根据id查询数据节点是否存在  存在则不继续查询下去
			int count = jdbcAvicit.getJdbcTemplate().queryForInt("SELECT COUNT(1) from LANTOP_ARCHIVE_CLASS where ARCHIVE_TYPE = '2' and ID = '"+rid+"' \n");

			if (null != childCount2 && childCount2.longValue() > 0) {
				if (count == 0) {
					node.setState("open");
					node.setChildren(this.getTreeNodeToDataNodeInfoByInfsItera(orgId, archiveTpe, rid, sql, level));
				} else {
					node.setState("open");
				}
			} else {
				node.setState("open");
			}

			nodeList.add(node);
		}
		return nodeList;
	}

	//备份
	public List<TreeNode> getTreeNodeToDataNodeInfoByInfsIteraBack(String orgId, String archiveTpe, String parentId, String sql, int level) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		if ("".equals(sql)) {
			return nodeList;
		}
		if (level == 0) {
			return null;
		}
		level--;

		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdPathsToDataNode(parentId, sql);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			/*
			 * if (null != childCount2 && childCount2.longValue() > 0) { node.setChildren(cnodes); node.setState("open"); } else { node.setState("open"); }
			 */

			if (null != childCount2 && childCount2.longValue() > 0) {
				if (level > 0) {
					node.setState("open");
				} else {
					node.setState("closed");
				}

				node.setChildren(this.getTreeNodeToDataNodeInfoByInfs(orgId, archiveTpe, rid, sql, level));
			} else {
				node.setState("open");
			}

			nodeList.add(node);
		}
		return nodeList;
	}








	/**
	 * 通过orgid,Type, parentId获得树节点
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华
	 * @param orgId
	 * @param archiveTpe
	 * @param parentId
	 * @return List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeToDataNodeInfoByInfsToModelFolder(String orgId, String archiveTpe, String parentId, String sql, int level) {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		if ("".equals(sql)) {
			return nodeList;
		}
		if (level == 0) {
			return null;
		}
		level--;

		List<Map<String, Object>> archiveClassList = this.findNodesByParentIdPathsToDataNodeToModelFolder(parentId, sql);
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			/*
			 * if (null != childCount2 && childCount2.longValue() > 0) { node.setChildren(cnodes); node.setState("open"); } else { node.setState("open"); }
			 */

			if (null != childCount2 && childCount2.longValue() > 0) {
				if (level > 0) {
					node.setState("open");
				} else {
					node.setState("closed");
				}
				node.setChildren(this.getTreeNodeToDataNodeInfoByInfsToModelFolder(orgId, archiveTpe, rid, sql, level));
			} else {
				node.setState("open");
			}

			nodeList.add(node);
		}
		return nodeList;
	}

	/**
	 * 根据orgid,archiveType 查询数据
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华
	 * @param parentId
	 * @param orgId
	 * @param archiveType
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> findNodesByParentIdPathsToDataNode(String parentId, String sql) {
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, parentId, parentId);
		return list;
	}

	/**
	 * 根据orgid,archiveType 查询数据
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * @author 钟一华
	 * @param parentId
	 * @param orgId
	 * @param archiveType
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> findNodesByParentIdPathsToDataNodeToModelFolder(String parentId, String sql) {
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, parentId);
		return list;
	}

	/**
	 * 获得查询语句
	 * @author 钟一华 
	 * @param orgId
	 * @param archiveType
	 * @return String
	 * @throws
	 */
	public String getSelectSqlByOrgIdType(String orgId, String archiveType, List<String> authIds, String jtbFlag) {
		List<Map<String, Object>> list = this.getArchiveClassTreeNodeToDataNodePathByOrgIdType(orgId, archiveType, jtbFlag);
		if (list.size() > 0) {
			StringBuffer sb = new StringBuffer();
			String path = "";
			Map<String, Object> map = new HashMap<String, Object>();
			sb.append(authIds.get(0) + ",");
			sb.append(" A AS (SELECT T.* FROM LANTOP_ARCHIVE_CLASS T \n");
			if (list.size() > 0) {
				sb.append(" WHERE (");
			}
			for (int i = 0; i < list.size(); i++) {
				map = list.get(i);
				path = map.get("ARCHIVE_CLASS_NODE_PATH").toString();
				sb.append("INSTR('" + path + "', T.ARCHIVE_CLASS_NODE_PATH) > 0 ");
				if (list.size() - 1 > i) {
					sb.append(" OR ");
				}
			}
			sb.append(") \n");
			if (null != authIds && !"".equals(authIds)) {
				sb.append("AND ID IN (" + authIds.get(1) + ")");
			} else {
				sb.append("AND 1=2");
			}
			sb.append("UNION ALL \n");
			sb.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T WHERE (");
			for (int j = 0; j < list.size(); j++) {
				map = list.get(j);
				path = map.get("ARCHIVE_CLASS_NODE_PATH").toString();
				sb.append("INSTR(T.ARCHIVE_CLASS_NODE_PATH,'" + path + "') > 0 ");
				if (list.size() - 1 > j) {
					sb.append(" OR ");
				}
			}
			sb.append(") AND T.ARCHIVE_CLASS_NODE_PATH NOT IN (\n");
			for (int k = 0; k < list.size(); k++) {
				map = list.get(k);
				path = map.get("ARCHIVE_CLASS_NODE_PATH").toString();
				sb.append("'" + path + "'");
				if (list.size() - 1 > k) {
					sb.append(" , ");
				}
			}
			sb.append(") \n");
			if (null != authIds && !"".equals(authIds)) {
				sb.append("AND ID IN (" + authIds.get(1) + ")");
			} else {
				sb.append("AND 1=2");
			}
			sb.append("), \n");

			// 加入条目节点的对应节点信息
			sb.append("T5 AS \n");
			sb.append(" (SELECT LAS.* \n");
			sb.append("    FROM LANTOP_USER_AUTH_EXTEND_DATA T \n");
			sb.append("    LEFT JOIN LANTOP_ARCHIVE_CLASS LAS \n");
			sb.append("      ON LAS.ID = T.ARCHIVE_CLASS_ID \n");
			sb.append("   WHERE (T.START_DATE <= \n");
			sb.append("         TO_DATE(TO_CHAR(SYSDATE, 'yyyy-mm-dd'), 'yyyy-mm-dd') OR \n");
			sb.append("         T.START_DATE IS NULL) \n");
			sb.append("     AND (T.END_DATE >= \n");
			sb.append("         TO_DATE(TO_CHAR(SYSDATE, 'yyyy-mm-dd'), 'yyyy-mm-dd') OR \n");
			sb.append("         T.END_DATE IS NULL)), \n");
			sb.append("T4 AS \n");
			sb.append(" (SELECT * \n");
			sb.append("    FROM LANTOP_ARCHIVE_CLASS T \n");
			sb.append("  CONNECT BY PRIOR T.ID = T.PARENT_ID \n");
			sb.append("   START WITH T.PARENT_ID = ?  AND T.ORG_ID = '" + orgId + "'), \n");
			sb.append(" T7 AS \n");
			sb.append(" (SELECT T5.* \n");
			sb.append("    FROM T5,T4 \n");
			sb.append("   WHERE INSTR(T5.ARCHIVE_CLASS_NODE_PATH, T4.ARCHIVE_CLASS_NODE_PATH) > 0 \n");
			sb.append("    AND  INSTR('" + archiveType + "',T4.ARCHIVE_TYPE) > 0 \n");
			sb.append("   ), \n");
			sb.append(" \n");
			sb.append("T3 AS \n");
			sb.append(" (SELECT T4.* \n");
			sb.append("    FROM T7, T4 \n");
			sb.append("   WHERE INSTR(T7.ARCHIVE_CLASS_NODE_PATH, T4.ARCHIVE_CLASS_NODE_PATH) > 0), \n");
			sb.append(" \n");
			sb.append(" \n");
			sb.append("T6 AS \n");
			sb.append(" (SELECT * FROM A UNION SELECT * FROM T3) \n");

			sb.append("SELECT (SELECT COUNT(*) FROM T6 LAC2 WHERE LAC2.PARENT_ID = LAC1.ID) CHILD_COUNT, \n");
			sb.append("       LAC1.* \n");
			sb.append("  FROM T6 LAC1 \n");
			sb.append(" WHERE LAC1.PARENT_ID = ?  AND LAC1.ORG_ID = '" + orgId + "'\n");
			sb.append(" ORDER BY LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC \n");
			return sb.toString();
		} else {
			return "";
		}

	}

	/**
	 * 根据节点id获得当前节点下最大节点排序值
	 */
	public int getMaxNodeSortNumber(String id) {
		String sql = "select max(lac.node_sort_number) from (select (select count(*) from lantop_archive_class lac2 where lac2.parent_id = lac1.id) child_count, lac1.* from lantop_archive_class lac1 where lac1.parent_id = '"+id+"') lac";
		int number = this.jdbcAvicit.getJdbcTemplate().queryForObject(sql,Integer.class);
		return number;
	}

	/**
	 * 删除指定的档案分类树节点信息
	 * @author 钟一华 
	 * @param id
	 * @throws Exception void
	 * @throws
	 */
	@Override
	public void deleteArchiveClassByIntfs(String orgId, String deptId, String sysId, String id) throws Exception {
		List<Map<String, Object>> lacList = this.getListByParentId(id);
		if (lacList.size() > 0) {
			for (int i = 0; i < lacList.size(); i++) {
				if (lacList.get(i).get("ARCHIVE_CLASS_NODE_TYPE").toString().equals("2")) {
					this.commTableManagerIntfsService.deleteCbbTabNodeByNodeIdByIntfs(orgId, deptId, sysId, lacList.get(i).get("id").toString());
				}
				this.deleteArchiveClassByIntfs(orgId, deptId, sysId, lacList.get(i).get("id").toString());
			}
		}
		this.deleteTreeNodeById(orgId, deptId, id);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("nodeId", id);
		// 删除节点配置的权限数据
		userAuthIntfsService.deleteAuthByNodeIdByIntfs(orgId, deptId, sysId, param);
	}

	/**
	 * 通过id删除节点
	 * @author 钟一华
	 * @param id void
	 * @throws
	 */
	public void deleteTreeNodeById(String orgId, String deptId, String id) throws Exception {
		String findSql = "sELECT * FROM LANTOP_ARCHIVE_CLASS WHERE ID = ?";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(findSql, id);
		if (list.size() > 0) {
			Map<String, Object> map = list.get(0);
			String type = map.get("ARCHIVE_CLASS_NODE_TYPE").toString();
			if (type.equals("2")) {
				this.commTableManagerIntfsService.deleteCbbTabNodeByNodeIdByIntfs(orgId, deptId, "", id);
			}
		}
		String sql = "DELETE FROM LANTOP_ARCHIVE_CLASS WHERE ID = ?";
		this.jdbcAvicit.getJdbcTemplate().update(sql, id);
		SysLogUtil.log("档案分类树管理模块", "删除档案分类记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 通过parentId获得子节点集合
	 * @author 钟一华
	 * @param pId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> getListByParentId(String pId) {
		String sql = "select * from lantop_archive_class where parent_id = ?";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, pId);
		return list;
	}

	/**
	 * 获取子节点,对当前登陆用户的组织id和部门id进行过滤,只查询当前挡路用户组织和部门下的节点
	 * 获取档案分类树信息：树形展示（文件夹、模板、数据节点、物理表）
	 * 被调用方法getTreeNodeByOrgIdDeptId();
	 * @param parentId
	 * @return 子节点集合
	 */
	public List<Map<String, Object>> findNodesByParentId(String orgId, String parentId) {
		if ("".equals(parentId)) {
			parentId = "ROOT";
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select (select count(*)\n");
		sbSql.append("from LANTOP_ARCHIVE_NODE_TAB_V LAC2\n");
		sbSql.append("where LAC2.PARENT_ID = LAC1.ID\n");
		sbSql.append("and LAC2.ORG_ID = ?) CHILD_COUNT,\n");
		sbSql.append("LAC1.*\n");
		sbSql.append("from LANTOP_ARCHIVE_NODE_TAB_V LAC1\n");
		sbSql.append("where LAC1.PARENT_ID = ? and LAC1.ORG_ID = ? AND LAC1.ARCHIVE_CLASS_NODE_CODE <> 'LANTOP_PUB_FIELD'\n");
		sbSql.append("order by LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC");
		Object[] objs = new Object[3];
		objs[0] = orgId;
		objs[1] = parentId;
		objs[2] = orgId;
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), objs);
		return list;
	}

	/**
	 * 根据orgid和type获得路径信息
	 * @author 钟一华
	 * @param orgId
	 * @param type
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> getArchiveClassTreeNodeToDataNodePathByOrgIdType(String orgId, String type, String jtbFlag) {
		StringBuffer sbSql = new StringBuffer();
		if (null != jtbFlag && !"".equals(jtbFlag) && !"null".equals(jtbFlag)) {
			sbSql.append("SELECT * FROM (\n");
			sbSql.append("SELECT * FROM LANTOP_ARCHIVE_CLASS TT\n");
			sbSql.append("CONNECT BY PRIOR TT.ID = TT.PARENT_ID\n");
			sbSql.append("START WITH TT.ID IN (\n");
			sbSql.append("SELECT T.ID FROM LANTOP_ARCHIVE_CLASS T WHERE INSTR(?, T.ARCHIVE_TYPE) > 0) ) LAC WHERE LAC.ARCHIVE_CLASS_NODE_TYPE = '2' AND UPPER(REPLACE(REPLACE(LAC.REMARK, CHR(10), ''), ' ', '')) = '" + jtbFlag.trim().toUpperCase() + "'");
		} else {
			sbSql.append("SELECT LAC.ARCHIVE_CLASS_NODE_PATH\n");
			sbSql.append("FROM LANTOP_ARCHIVE_CLASS LAC\n");
			sbSql.append("WHERE INSTR(?, LAC.ARCHIVE_TYPE) > 0\n");
		}
		sbSql.append(" AND LAC.ORG_ID = ?");
		Object[] objs = new Object[2];
		objs[0] = type;
		objs[1] = orgId;
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), objs);
		return list;
	}

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	/**
	 * 创建档案分类树节点信息
	 * @author 钟一华 
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param id
	 * @param nodeName
	 * @param parentNodePath
	 * @throws Exception void
	 * @throws
	 */
	@Override
	public String createArchiveClassByIntfs(String orgId, String deptId, String sysId, String nodeName, String parentNodePath, String nodeType, String loginUserId, String loginIp) throws Exception {
		LantopArchiveClass lac = new LantopArchiveClass();
		PojoUtil.setSysProperties(lac, OpType.insert);
		lac.setOrgId(orgId);
		lac.setDeptId(deptId);
		lac.setSysId(sysId);
		String id = ComUtil.getId();
		lac.setId(id);
		lac.setArchiveClassNodeName(nodeName);
		lac.setArchiveClassNodeType(nodeType);
		lac.setArchiveClassNodeCode(Pinyin4jUtil.getPinYinHeadChar(lac.getArchiveClassNodeName()));
		lac.setArchiveClassNodePath(parentNodePath + "/" + id);
		// 获得parentId
		String parentSql = "SELECT ID FROM LANTOP_ARCHIVE_CLASS WHERE ARCHIVE_CLASS_NODE_PATH = ?";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(parentSql, parentNodePath);
		Map<String, Object> map = list.get(0);
		String parentId = map.get("id").toString();
		lac.setParentId(parentId);
		if (nodeType.equals("2")) {
			List<Map<String, Object>> modelList = this.getModelData(parentId);
			Map<String, Object> m = modelList.get(0);
			String modelId = m.get("ID").toString();
			List<Map<String, Object>> tableIdsList = this.commTableManagerIntfsService.getCbbTableIdsByNodeIdByIntfs(orgId, deptId, sysId, modelId);
			for (int i = 0; i < tableIdsList.size(); i++) {
				Map<String, Object> tableMap = tableIdsList.get(i);
				String tableId = (String) tableMap.get("TABLE_ID");
				String tabFlag = (String) tableMap.get("TAB_FLAG");
				Map<String, Object> param = new HashMap<String, Object>();
				param.put("TAB_FLAG", tabFlag);
				this.commTableManagerIntfsService.createCbbTabNodeByIntfs(orgId, deptId, sysId, id, tableId, loginUserId, loginIp, param);
			}
		}
		// 通过parentId获得最大顺序值
		int nodeSortNumber = this.getMaxNodeSortNumber(parentId);
		// 转换类型,并且将查询到的最大值+1赋值给新数据
		long number = Long.valueOf(nodeSortNumber + 1);
		BigDecimal sortNumber = BigDecimal.valueOf(number);
		lac.setNodeSortNumber(sortNumber);
		this.hibernateDao.save(lac);
		SysLogUtil.log(lac, null, OpType.insert, OpResult.success);
		return id;
	}

	/**
	 * 通过id 获取 模版数据信息集合
	 * @param id
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getModelData(String id) throws Exception {
		String sql = "SELECT * FROM LANTOP_ARCHIVE_CLASS L WHERE L.ID = ? AND (L.ARCHIVE_TYPE != '0' AND L.ARCHIVE_TYPE IS NOT NULL)";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, id);
		if (list.size() < 1) {
			String findSql = "SELECT * FROM LANTOP_ARCHIVE_CLASS L WHERE ID = ?";
			List<Map<String, Object>> l = this.jdbcAvicit.getJdbcTemplate().queryForList(findSql, id);
			Map<String, Object> m = l.get(0);
			String pid = m.get("PARENT_ID").toString();
			return this.getModelData(pid);
		} else {
			return list;
		}
	}

	/**
	 * 获取档案分类树中所给节点的上一级指定物理表的节点信息
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassListParentNodeInfoForTableByIntfs(String archiveClassId) throws Exception {
		String sql = "SELECT LAC.* FROM LANTOP_ARCHIVE_CLASS LAC WHERE LAC.ID = ?";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, archiveClassId);
		String id = "";
		if (list.size() > 0) {
			Map<String, Object> map = list.get(0);
			id = map.get("id").toString();
		}
		return this.getListByIdForIterator(id);
	}

	/**
	 * 递归循环查询父节点是否存在库表关联信息
	 * @author 钟一华
	 * @param pId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	public List<Map<String, Object>> getListByIdForIterator(String pId) throws Exception {
		String sql = "select * from lantop_archive_class where id = ?";
		List<Map<String, Object>> resultList = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, pId);
		Map<String, Object> map = null;
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		String parentId = "";
		if (resultList.size() > 0) {
			map = resultList.get(0);
			String id = map.get("id").toString();
			parentId = map.get("parent_id").toString();
			String sysId = map.get("sys_id").toString();
			String orgId = map.get("org_id").toString();
			String deptId = map.get("dept_id").toString();
			list = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, id, "");
		}
		if (list.size() > 0) {
			return resultList;
		} else {
			resultList = this.getListByIdForIterator(parentId);
		}
		return resultList;
	}

	/**
	 * 获取档案分类树信息：按照档案类型（多个用英文逗号隔开）、节点类型来获取（多个用英文逗号隔开）
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassListInfoByIntfs(String orgId, String deptId, String archiveType, String archiveClassNodeType) throws Exception {
		String[] types = null;
		String[] nodeTypes = null;
		String sql = "select * from lantop_archive_class where ORG_ID = '" + orgId + "'";
		if (null != archiveType && !"".equals(archiveType)) {
			types = archiveType.split(";");
			sql += " AND ARCHIVE_TYPE IN (";
			for (int i = 0; i < types.length; i++) {
				sql += "'" + types[i] + "'";
			}
			sql += ")";
		} else {
			sql += " AND ARCHIVE_TYPE = ''";
		}
		if (null != archiveClassNodeType && !"".equals(archiveClassNodeType)) {
			nodeTypes = archiveClassNodeType.split(";");
			sql += " AND ARCHIVE_CLASS_NODE_TYPE IN (";
			for (int i = 0; i < nodeTypes.length; i++) {
				sql += "'" + nodeTypes[i] + "'";
			}
			sql += ")";
		} else {
			sql += " AND ARCHIVE_CLASS_NODE_TYPE = ''";
		}
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		return list;
	}

	/**
	 * 删除文件管理冗余树节点数据
	 * @author 钟一华
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param param
	 * 			(key: FILE_NAME 名称	value: 个人文件/部门文件 key: FILE_CODE 编号	value: GRWJ/BMWJ)
	 * @throws Exception void
	 */
	@Override
	public void deleteRedundancyTreeData(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		String fileName = (String) param.get("FILE_NAME");
		String fileCode = (String) param.get("FILE_CODE");
		if (null != fileName && !"".equals(fileName) && null != fileCode && !"".equals(fileCode)) {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("SELECT * FROM LANTOP_ARCHIVE_CLASS T\n");
			sbSql.append("WHERE ORG_ID = '" + orgId + "' AND DEPT_ID = '" + deptId + "' AND SYS_ID = '" + sysId + "'\n");
			sbSql.append("AND ARCHIVE_CLASS_NODE_NAME = '" + fileName + "' AND ARCHIVE_CLASS_NODE_CODE = '" + fileCode + "'");
			List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				String parentId = (String) map.get("PARENT_ID");
				LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, parentId);
				if (null == lac) {
					StringBuffer sb = new StringBuffer();
					sb.append("SELECT T.* FROM LANTOP_ARCHIVE_CLASS T\n");
					sb.append("CONNECT BY PRIOR T.ID = T.PARENT_ID\n");
					sb.append("START WITH T.PARENT_ID = '" + parentId + "'");
					List<Map<String, Object>> lacList = this.jdbcAvicit.getJdbcTemplate().queryForList(sb.toString());
					for (int j = 0; j < lacList.size(); j++) {
						Map<String, Object> lacMap = lacList.get(j);
						LantopArchiveClass deleteLac = this.hibernateDao.get(LantopArchiveClass.class, (String) lacMap.get("ID"));
						this.hibernateDao.delete(deleteLac);
						SysLogUtil.log(deleteLac, null, OpType.delete, OpResult.success);
					}
				}
			}
		}
		// 清理冗余档案分类树数据
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_ARCHIVE_CLASS LAC WHERE LAC.ID NOT IN (\n");
		sbSql.append("SELECT T.ID FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("CONNECT BY PRIOR T.ID = T.PARENT_ID\n");
		sbSql.append("START WITH T.PARENT_ID = 'ROOT'\n");
		sbSql.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("档案分类树模块", "删除档案分类树记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());

	}

	/**
	 * 通过数据节点id获取树结构数据(向上查)
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeByIntfs(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		List<TreeNode> treeNodes = new ArrayList<TreeNode>();
		String nodeId = "";
		if (null != param) {
			nodeId = (String) param.get("NODE_ID");
		}
		String nodePath = "";
		if (null != nodeId && !"".equals(nodeId)) {
			LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, nodeId);
			if (null != lac) {
				nodePath = lac.getArchiveClassNodePath();
			}
		}
		if (!"".equals(nodePath)) {
			String sql = this.getTreeNodeSqlByNodePath(nodePath);
			treeNodes = this.getTreeNodeBySqlByParentId(sql, "ROOT");
		}
		return treeNodes;
	}

	/**
	 * 通过nodepath获取查询树sql
	 * @param nodePath
	 * @return
	 * @throws Exception
	 */
	public String getTreeNodeSqlByNodePath(String nodePath) throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("WITH FROMDATA AS (SELECT * FROM LANTOP_ARCHIVE_CLASS T \n");
		sb.append("WHERE INSTR('" + nodePath + "', T.ARCHIVE_CLASS_NODE_PATH) > 0 \n");
		sb.append("CONNECT BY PRIOR T.ID = T.PARENT_ID \n");
		sb.append("START WITH PARENT_ID = 'ROOT') \n");
		sb.append("SELECT (SELECT COUNT(*) FROM FROMDATA LAC WHERE LAC.PARENT_ID = LAC1.ID) CHILD_COUNT, LAC1.* FROM FROMDATA LAC1 \n");
		sb.append("WHERE LAC1.PARENT_ID = ?");
		return sb.toString();
	}

	/**
	 * 通过父节点获取树结构信息集合
	 * @param sql
	 * @param pId
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	public List<TreeNode> getTreeNodeBySqlByParentId(String sql, String pId) throws Exception {
		List<TreeNode> nodeList = new ArrayList<TreeNode>();
		if ("".equals(sql)) {
			return nodeList;
		}
		List<Map<String, Object>> archiveClassList = this.jdbcAvicit.getJdbcTemplate().queryForList(sql, new Object[] {pId});
		// 将业务数据格式转换成esayui树形格式，此处封装了一个TreeNodeVo节点
		for (Map<String, Object> row : archiveClassList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("archive_class_node_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			String archiveType = (String) row.get("ARCHIVE_TYPE");
			String nodeType = (String) row.get("ARCHIVE_CLASS_NODE_TYPE");
			String rootId = (String) row.get("PARENT_ID");
			// 根据节点类型,设置节点图标
			if (null != rootId && "ROOT".equals(rootId)) { // 根节点
				node.setIconCls("icon-im-newnorg");
			} else if (null != archiveType && "-1".equals(archiveType) && null == nodeType) { // 档案类型 -1 物理表
				node.setIconCls("icon-im-newntable");
			} else if (null != archiveType && "0".equals(archiveType) && null == nodeType) { // 0 模版文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != archiveType && "1".equals(archiveType) && null == nodeType) { // 1 标识文件
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "2".equals(archiveType) && null == nodeType) { // 2 档案
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "3".equals(archiveType) && null == nodeType) { // 3 专题库
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "4".equals(archiveType) && null == nodeType) { // 4 多媒体
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "5".equals(archiveType) && null == nodeType) { // 5 项目归档计划
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "6".equals(archiveType) && null == nodeType) { // 6 管务
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "7".equals(archiveType) && null == nodeType) { // 7 其他
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "8".equals(archiveType) && null == nodeType) { // 8 资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "9".equals(archiveType) && null == nodeType) { // 9 图书
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "10".equals(archiveType) && null == nodeType) { // 10 虚拟表
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != archiveType && "TECH".equals(archiveType) && null == nodeType) { // TECH技术资料
				node.setIconCls("icon-im-newnmodulelib");
			} else if (null != nodeType && "1".equals(nodeType)) { // 节点类型 1 文件夹
				node.setIconCls("icon-im-newnmodulefile");
			} else if (null != nodeType && "2".equals(nodeType)) { // 数据节点
				node.setIconCls("icon-im-newndatanode");
			}
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnodes = this.getTreeNodeBySqlByParentId(sql, rid);
				node.setChildren(cnodes);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodeList.add(node);
		}
		return nodeList;
	}

	/**
	 * 查询档案分类树信息
	 * @param param
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassDataByParam(Map<String, Object> param) throws Exception {
		if (null != param) {
			String deptId = (String) param.get("DEPT_ID");
			String orgId = (String) param.get("ORG_ID");
			String sysId = (String) param.get("SYS_ID");
			String nodeCode = (String) param.get("NODE_CODE");
			String archiveType = (String) param.get("ARCHIVE_TYPE");
			String sql = "SELECT * FROM LANTOP_ARCHIVE_CLASS LAC WHERE 1 = 1 ";
			if (null != deptId && !"".equals(deptId)) {
				sql += " AND LAC.DEPT_ID = '" + deptId + "'";
			}
			if (null != orgId && !"".equals(orgId)) {
				sql += " AND LAC.ORG_ID = '" + orgId + "'";
			}
			if (null != sysId && !"".equals(sysId)) {
				sql += " AND LAC.SYS_ID = '" + sysId + "'";
			}
			if (null != nodeCode && !"".equals(nodeCode)) {
				sql += " AND LAC.ARCHIVE_CLASS_NODE_CODE = '" + nodeCode + "'";
			}
			if (null != archiveType && !"".equals(archiveType)) {
				sql += " AND LAC.ARCHIVE_TYPE = '" + archiveType + "'";
			}
			List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
			return list;
		} else {
			return null;
		}
	}

	/**
	 * 通过模板文件夹ID获取数据节点集合 
	 * @param id
	 * @return
	 * @throws Exception List<String>
	 * @throws
	 */
	@Override
	public List<String> getDataNodeBytableInfoId(String id) throws Exception {
		List<String> list = new ArrayList<String>();
		StringBuffer sql = new StringBuffer();
		sql.append("WITH T1 AS");
		sql.append(" (SELECT T.ARCHIVE_CLASS_NODE_PATH");
		sql.append("    FROM LANTOP_ARCHIVE_CLASS T");
		sql.append("   WHERE T.ID = '" + id + "')");
		sql.append("SELECT LAC.ID");
		sql.append("  FROM LANTOP_ARCHIVE_CLASS LAC, T1");
		sql.append(" WHERE INSTR(LAC.ARCHIVE_CLASS_NODE_PATH, T1.ARCHIVE_CLASS_NODE_PATH) > 0 AND LAC.ARCHIVE_CLASS_NODE_TYPE = '2'");
		List<Map<String, Object>> listMap = this.jdbcAvicit.getJdbcTemplate().queryForList(sql.toString());
		for (int i = 0; i < listMap.size(); i++) {
			Map<String, Object> map = listMap.get(i);
			list.add(String.valueOf(map.get("ID")));
		}
		return list;
	}

	/**
	 * 通过节点集合返回数据节点信息
	 * @param nodeId
	 * @return
	 * @throws Exception Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, Object> getDataNodeInfoByParam(Map<String, Object> param) throws Exception {
		Map<String, Object> p = new HashMap<String, Object>();
		if (param.containsKey("treeNodeList")) {
			List<Map<String, Object>> treeNodeIdList = (List<Map<String, Object>>) param.get("treeNodeList");
			int dataCount = 0;
			for (int i = 0; i < treeNodeIdList.size(); i++) {
				Map<String, Object> mm = treeNodeIdList.get(i);
				Object tabFlag = mm.get("TAB_FLAG");
				if (null != tabFlag && !"".equals(tabFlag) && ("0".equals(tabFlag) || "1".equals(tabFlag))) {
					dataCount++;
				}
			}
			p.put("dataCount", dataCount);
		}
		if (param.containsKey("nodeId")) {
			String nodeId = (String) param.get("nodeId");
			Map<String, Object> modelMap = this.getModelFolderInfoByNodeId(nodeId);
			p.put("archiveType", modelMap.get("ARCHIVE_TYPE"));
		}
		return p;
	}

	/**
	 * 根据节点id获取模板文件夹信息
	 * @param nodeId
	 * @return
	 * @throws Exception Map<String,Object>
	 * @throws
	 */
	public Map<String, Object> getModelFolderInfoByNodeId(String nodeId) throws Exception {
		String sql = "SELECT * FROM LANTOP_ARCHIVE_CLASS WHERE ID = '" + nodeId + "'";
		Map<String, Object> map = this.jdbcAvicit.getJdbcTemplate().queryForMap(sql);
		Object archiveType = map.get("ARCHIVE_TYPE");
		if (null != archiveType && !"".equals(archiveType) && !"0".equals(archiveType)) {
			return map;
		} else {
			String id = (String) map.get("PARENT_ID");
			return this.getModelFolderInfoByNodeId(id);
		}
	}

	/**
	 * 根据所传节点集合追加树节点
	 * @param tns
	 * @param param
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getAppendTreeNodeByParamTreeList(List<TreeNode> tns, Map<String, Object> param) throws Exception {
		String sql = "SELECT * FROM LANTOP_ARCHIVE_CLASS T WHERE  T.ARCHIVE_TYPE = 'TECH'";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		for (int i = 0; i < tns.size(); i++) {
			TreeNode tn = tns.get(i);
			List<TreeNode> newTns = new ArrayList<TreeNode>();
			for (int j = 0; j < list.size(); j++) {
				TreeNode newTn = new TreeNode();
				Map<String, Object> map = list.get(j);
				newTn.setId((String) map.get("ID"));
				newTn.setIconCls("");
				newTn.setText((String) map.get("ARCHIVE_CLASS_NODE_NAME"));
				newTn.setAttributes(map);
				newTns.add(newTn);
			}
			tn.setChildren(newTns);
		}
		return tns;
	}

	/**
	 * 获取档案分类树结构(只包含到模板文件夹)
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param archiveType
	 * @param param
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeByArchiveTypeToModelFolder(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> param) throws Exception {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("targetId", param.get("targetId"));
		params.put("targetType", param.get("targetType"));
		params.put("orgId", orgId);
		params.put("deptId", deptId);
		params.put("sysId", sysId);
		param.put("orgIdentity", (String) params.get("orgIdentity"));
		List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveClassId(params);
		String sql = this.getSelectSqlByOrgIdArchiveType(orgId, archiveType, authIds);
		int level = 1;// 树展开的层级
		String parentId = (String) param.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
			level = 2;
		}
		List<TreeNode> nodeList = this.getTreeNodeToDataNodeInfoByInfsToModelFolder(orgId, archiveType, parentId, sql, level);
		return nodeList;
	}

	/**
	 * 获得查询语句
	 * @author 钟一华 
	 * @param orgId
	 * @param archiveType
	 * @return String
	 * @throws
	 */
	public String getSelectSqlByOrgIdArchiveType(String orgId, String archiveType, List<String> authIds) {
		List<Map<String, Object>> list = this.getArchiveClassTreeNodeToDataNodePathByOrgIdType(orgId, archiveType, "");
		if (list.size() > 0) {
			StringBuffer sb = new StringBuffer();
			if (authIds.size() > 0) {
				sb.append(authIds.get(0) + ",");
			} else {
				sb.append(" WITH ");
			}
			String path = "";
			Map<String, Object> map = new HashMap<String, Object>();
			sb.append(" A AS (SELECT T.* FROM LANTOP_ARCHIVE_CLASS T \n");
			if (list.size() > 0) {
				sb.append(" WHERE (");
			}
			for (int i = 0; i < list.size(); i++) {
				map = list.get(i);
				path = map.get("ARCHIVE_CLASS_NODE_PATH").toString();
				sb.append("INSTR('" + path + "', T.ARCHIVE_CLASS_NODE_PATH) > 0 ");
				if (list.size() - 1 > i) {
					sb.append(" OR ");
				}
			}
			sb.append(") \n");
			if (authIds.size() > 0) {
				sb.append("AND ID IN (" + authIds.get(1) + ")");
			} else {
				sb.append("AND 1=2");
			}
			sb.append(") \n");
			sb.append("SELECT (SELECT COUNT(*) FROM A LAC2\n");
			sb.append("WHERE LAC2.PARENT_ID=LAC1.ID)\n");
			sb.append("CHILD_COUNT,LAC1.* FROM A LAC1\n");
			sb.append("WHERE LAC1.PARENT_ID = ? ORDER BY LAC1.NODE_SORT_NUMBER ASC, LAC1.CREATION_DATE ASC");
			return sb.toString();
		} else {
			return "";
		}
	}

	/**
	 * 获取选中节点和节点下子节点数据
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param id
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getSelectNodeChild(String orgId, String deptId, String sysId, String id) throws Exception {
		LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, id);
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select *\n");
		sbSql.append("  from lantop_archive_class c\n");
		sbSql.append(" where instr(c.archive_class_node_path,\n");
		sbSql.append("             '" + lac.getArchiveClassNodePath() + "') > 0\n");
		sbSql.append("   and c.id not in\n");
		sbSql.append("       (select lac.id\n");
		sbSql.append("          from lantop_archive_class lac\n");
		sbSql.append("        connect by prior lac.id = lac.parent_id\n");
		sbSql.append("         start with id in\n");
		sbSql.append("                    (select a.id\n");
		sbSql.append("                       from lantop_archive_class a\n");
		sbSql.append("                      where a.archive_class_node_code in ('GRWJ', 'BMWJ') OR a.archive_type = '10'))");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		return list;
	}

	/**
	 * 根据sql语句获取档案分类树信息集合
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param condition
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getLantopArchiveClassByCondition(String orgId, String deptId, String sysId, String condition) throws Exception {
		String sql = "SELECT * FROM LANTOP_ARCHIVE_CLASS WHERE ORG_ID = '" + orgId + "' AND DEPT_ID = '" + deptId + "' AND SYS_ID = '" + sysId + "'" + condition;
		return this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
	}

	/**
	 * 根据tableId获取模板文件夹节点信息
	 * @param nodeId
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getArchiveClassTreeNodeByTableId(String tableId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT LAC.*\n");
		sbSql.append("  FROM LANTOP_ARCHIVE_CLASS LAC\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql.append("    ON CTN.NODE_ID = LAC.ID\n");
		sbSql.append(" WHERE CTN.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   AND LAC.ARCHIVE_CLASS_NODE_TYPE IS NULL\n");
		sbSql.append("   AND LAC.ARCHIVE_TYPE IS NOT NULL");
		List<Map<String, Object>> list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return list;
	}

	/**
	 * 根据nodeId获取模版文件夹名称
	 * @author 郭亮
	 * @param nodeId
	 * @return
	 * @throws Exception String
	 */
	@Override
	public String getModelFileNameByNodeId(String nodeId) throws Exception {
		String pathName = "";// 路径名称
		LantopArchiveClass lac = this.hibernateDao.get(LantopArchiveClass.class, nodeId); // 数据节点
		StringBuffer sbSql = new StringBuffer();
		List<String> list = new ArrayList<String>();
		if (lac != null) {
			sbSql.append("SELECT T.ARCHIVE_CLASS_NODE_NAME\n");
			sbSql.append(" FROM LANTOP_ARCHIVE_CLASS T\n");
			sbSql.append(" WHERE INSTR('" + lac.getArchiveClassNodePath() + "',T.ARCHIVE_CLASS_NODE_PATH) > 0\n");
			sbSql.append(" AND (T.ARCHIVE_TYPE = '0' OR T.ARCHIVE_TYPE = '1' OR T.ARCHIVE_TYPE = '2' OR");
			sbSql.append(" T.ARCHIVE_TYPE = '3' OR T.ARCHIVE_TYPE = '4' OR");
			sbSql.append(" T.ARCHIVE_TYPE = '5' OR T.ARCHIVE_TYPE = '6' OR");
			sbSql.append(" T.ARCHIVE_TYPE = '7' OR T.ARCHIVE_TYPE = '8' OR");
			sbSql.append(" T.ARCHIVE_TYPE = '9' OR T.ARCHIVE_CLASS_NODE_TYPE = '1' OR T.ARCHIVE_CLASS_NODE_TYPE = '2')");
			list = this.hibernateDao.findBySQL(sbSql.toString());
		}
		for (int i = 0; i < list.size(); i++) {
			if (i == 0) {
				pathName = list.get(i);
			} else {
				pathName = pathName + "\\" + list.get(i);
			}
		}
		return pathName;
	}

	/**
	 * 获取档案分类树指定的‘档案类型’信息：树形展示（文件夹、模板、数据节点）
	 * 根节点显示所传递档案类型对应的名称；
	 * @author 郭凯
	 * @param orgId
	 * @param deptId
	 * @param archiveType
	 * @return
	 * @throws Exception List<TreeNode>
	 * @throws
	 */
	@Override
	public List<TreeNode> getArchiveClassTreeNodeToDataNodeInfoByIntfss(String orgId, String deptId, String sysId, String archiveType, Map<String, Object> params) throws Exception{
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("targetId", params.get("targetId"));
		param.put("targetType", params.get("targetType"));
		param.put("orgId", orgId);
		param.put("deptId", deptId);
		param.put("sysId", sysId);
		param.put("orgIdentity", params.get("orgIdentity"));
		String jtbFlag = (String) params.get("jtbFlag");
		List<String> authIds = this.userAuthIntfsService.getNotAuthArchiveId(param);
		// 获得数据集合sql
		String sql = this.getSelectSqlByOrgIdType(orgId, archiveType, authIds, jtbFlag);
		int level = 1;// 树展开的层级
		String parentId = (String) params.get("rootId");
		// 加载的时候给你默认给顶级节点 id root
		if (parentId == null || "".equals(parentId)) {
			parentId = "ROOT";
			level = 3;
		}
		if (params.containsKey("TREE_LEVEL") && null != params.get("TREE_LEVEL")) {
			String treeLevel = (String) params.get("TREE_LEVEL");
			level = Integer.parseInt(treeLevel);
		}
		List<TreeNode> nodeList = this.getTreeNodeToDataNodeInfoByInfs(orgId, archiveType, parentId, sql, level);
		return nodeList;
	}

	/**
	 * @Description 判断是否为管理类文书类节点
	 * @return
	 * @Author zcl
	 * @Date 2020/1/9 14:03
	 **/
	public String isClericalClassTreeNode(String nodeId, String orgId, String tableId){
		String clericalClassName = "";
		String pClericalClassId = "";
		try {
			//1.获取文书类节点id
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("targetId", "1");//获取root权限
			param.put("targetType", "3");
			param.put("rootId", "");//rootId为空查询四层树结构
			param.put("orgIdentity", orgId);
			List<TreeNode> nodeList = this.getArchiveClassTreeNodeToDataNodeInfoByIntfsToStatics(orgId, "", "LANTOP", "2", param);
            here:
			if(nodeList.size() > 0){
				List<TreeNode> fourthNodeList = nodeList.get(0).getChildren().get(0).getChildren();
				for (int i = 0; i < fourthNodeList.size(); i++) {
					List<TreeNode> nodes = fourthNodeList.get(i).getChildren();
					for (int j = 0; j < nodes.size(); j++) {
						Map<String, Object> map = new HashMap<String, Object>();
						String nodeName = nodes.get(j).getText();
						String id = nodes.get(j).getId();
						if("文书".equals(nodeName)){
							pClericalClassId = id;
							break here;
						}
					}
				}
			}
			//2.获取所有文书类的节点，判断nodeId是否为文书类节点
			if(!StringUtils.isEmpty(pClericalClassId)){
				String sql = "SELECT * FROM CBB_TAB_NODE where TABLE_ID = '" + tableId + "'";
                List<Map<String, Object>> list = jdbcAvicit.queryForMap(sql, null);
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> map =  list.get(i);
                    String id = map.get("NODE_ID").toString();
                    if(pClericalClassId.equals(id)){
                        List<Map<String, Object>> treeMap = this.getArchiveClassListInfoByIntfs(nodeId);
                        clericalClassName = treeMap.get(0).get("ARCHIVE_CLASS_NODE_NAME").toString();
					}
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}
		return clericalClassName;
	}
}
